package com.tjetc.myservlet;

/**
 * 自定义HttpServlet
 * 我们就以Get为例 简化操作
 *
 * @author gaoyongxiang
 * @version v1.0
 * @date 2025/9/1
 */
public abstract class MyHttpServlet implements MyServlet {
    private static final String GET_METHOD = "GET";
    private static final String POST_METHOD = "POST";

    @Override
    public void service(MyHttpRequest request, MyHttpResponse response) throws Exception {
        // 模板设计模式
        // 根据不同的请求方式 来调用对应的处理方法
        if (GET_METHOD.equalsIgnoreCase(request.getMethod())) {
            // 根据动态绑定机制处理对应的业务
            doGet(request, response);
        } else if (POST_METHOD.equalsIgnoreCase(request.getMethod())) {
            doPost(request, response);
        }
    }

    protected abstract void doPost(MyHttpRequest request, MyHttpResponse response);

    protected abstract void doGet(MyHttpRequest request, MyHttpResponse response);
}